/*
 * Created on Fri Jun 08 2018 by Ronnie Ren (zhaosong.ren) from Accenture
 *
 * Copyright (c) 2018 DingXin information & technology limited company.
 */

import { Mock, Dev } from "../api-path/path";
import { APIPath, HTTPMethods } from "http-service";
import {s} from "@angular/core/src/render3";

declare const ENV: {
    environment: any,
    baseUrl: any
};

export class API {

    public Env: string;
    constructor() {
      this.Env = ENV.environment + "Env";
    }

    public path(param: {path: string,
      contentType?: string,
      method?: HTTPMethods,
      accept?: string,
      baseURL?: string,
      param?: string}) {
      let path = this.getEndpoint(param.path);
      if (param.param) {
        path += param.param;
      }
      return new APIPath({
        path: "",
        method: param.method,
        contentType: "application/json",
        baseURL: path
      });
    }

    public getEndpoint(name: string) {

      const apis = 'mockEnv' === this.Env ? Mock : Dev;

      let path = apis[name];
      if (!path) {
        return Mock[name];
      }

      return ENV.baseUrl + path;
      // return 'http://120.78.83.131/api2' + path;
    }


    // static SysUsers = new APIPath("");
    // static DownloadAttachment = new APIPath("");
}

